A core idea of software-defined networking (SDN) is separating network control forwarding logic from a physical forwarding plane. The network control forwarding logic is executed by a controller, and the physical forwarding plane is executed by a switching device. The switching device forwards a data packet according to a forwarding entry delivered by the controller. A most commonly used protocol between the controller and the switching device is referred to as the OpenFlow (OF) protocol. In the SDN, the controller can control resource allocation and network flow scheduling from a networkwide perspective and optimize resource utilization. However, how the controller obtains information about each network flow in the SDN is a vital issue.
In the prior art, the switching device collects a quantity of packets, a quantity of bytes, a quantity of flow entries, time, and other related information that are forwarded by a network flow that passes through each flow entry. In the OpenFlow standard, by exchanging a network flow statistics request message and a response message between the controller and the switching device, a quantity of packets, a quantity of bytes, a quantity of flow entries, time, and other related information that are forwarded by a match field for one or more flow entries of a specified field and that are in a flow table of the switching device may be obtained.
However, because a same flow entry may be successfully matched by multiple network flows, a statistical value of the flow entry is an aggregate value of the multiple network flows that successfully match the entry, rather than collecting information about each network flow. An amount of data when the switching device forwards a single network flow cannot be presented, and the information about each network flow cannot be calculated from statistical information of the flow entry. In addition, a same network flow may be matched by multiple flow entries of different flow tables in the switching device, causing repeated collection of forwarding data of each network flow by the switching device. In conclusion, by using the method in the prior art, accuracy of collecting network flow information by the switching device is not high.